//
//  CCTabBarViewController.m
//  CarCircle
//
//  Created by chenfangkun on 2019/1/11.
//  Copyright © 2019 chenfangkun. All rights reserved.
//

#import "CCTabBarViewController.h"
#import "CCNavigationController.h"
#import "CCHomeViewController.h"
#import "CCCircleCarViewController.h"
#import "CCMyViewController.h"

@interface CCTabBarViewController ()

@property (nonatomic,strong) CCHomeViewController *homeVC;
@property (nonatomic,strong) CCCircleCarViewController *circleCarVC;
@property (nonatomic,strong) CCMyViewController *myVC;

@end

@implementation CCTabBarViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self customizeTabBarAppearance];
}


- (void)customizeTabBarAppearance {
    NSArray *vcArray = @[self.homeVC,self.circleCarVC,self.myVC];
    NSArray *titleArray = @[@"首页",@"圈车",@"我"];
    NSArray *imageArray = @[@"",@"",@""];
    NSArray *selectImageArray = @[@"",@"",@""];
    
    for (int i = 0; i < 3; i++) {
        [self addChildViewController:vcArray[i] normalImage:imageArray[i] selectImage:selectImageArray[i] title:titleArray[i]];
    }
    
    [[UIBarButtonItem appearance]setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor lightGrayColor],NSFontAttributeName:KPWFont(10)} forState:UIControlStateNormal];
    [[UIBarButtonItem appearance]setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor redColor],NSFontAttributeName:KPWFont(10)} forState:UIControlStateSelected];
}
- (void)addChildViewController:(UIViewController *)childController normalImage:(NSString *)normalImage selectImage:(NSString *)selectImage title:(NSString *)title {
    childController.tabBarItem.image = [KPWImage(normalImage)imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    childController.tabBarItem.selectedImage = [KPWImage(selectImage)imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    childController.title = title;
    CCNavigationController *nav = [[CCNavigationController alloc]initWithRootViewController:childController];
    [self addChildViewController:nav];
}

#pragma mark -懒加载
- (CCHomeViewController *)homeVC {
    if (!_homeVC) {
        _homeVC = [[CCHomeViewController alloc]init];
    }
    return _homeVC;
}
- (CCCircleCarViewController *)circleCarVC {
    if (!_circleCarVC) {
        _circleCarVC = [[CCCircleCarViewController alloc]init];
    }
    return _circleCarVC;
}
- (CCMyViewController *)myVC {
    if (!_myVC) {
        _myVC = [[CCMyViewController alloc]init];
    }
    return _myVC;
}

@end
